import { createStore } from 'redux';
import { StoreType,ActionType } from '../interface'

// dispacth 触发reducer
// reducer  更改state的唯一方式
const reducer = (state:StoreType = initState, action:ActionType ) => {
    const { type } = action;

    if(type === 'CHANGE_USER_INFO') {
        return {
            ...state,
            userInfo: action.data
        }
    }
    
    return state
}

// 仓库的默认值
const initState = {
    userInfo: {}
}

const store = createStore(reducer);

export default store